package com.demo.springcloud.controller;

import com.demo.springcloud.pojo.CommonResult;
import com.demo.springcloud.pojo.Order;
import com.demo.springcloud.service.TOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TOrderController {

	@Autowired
	private TOrderService tOrderService;

	/**
	 * 查询所有记录
	 *
	 * @return 返回集合，没有返回空List
	 */
	@GetMapping("/list")
	public CommonResult getAll() {
		return new CommonResult(200, tOrderService.listAll().toString());
	}

	/**
	 * 用于测试本模块的是否搭建成功
	 *
	 * @param order
	 * @return
	 */
	@GetMapping("/test")
	public CommonResult insertTest(Order order) {
		tOrderService.insertTest(order);
		return new CommonResult(200, tOrderService.listAll().toString());
	}

	@GetMapping("/order")
	public CommonResult order(Order order) {
		int insert = tOrderService.insert(order);
		if (insert > 0) {
			return new CommonResult(200, "订单创建完成");
		}
		return new CommonResult(444, "订单创建失败");
	}

	@GetMapping("/updateTest")
	public CommonResult updateTest(Order order) {
		tOrderService.update(order.getId(), 1);
		return new CommonResult(200, tOrderService.listAll().toString());
	}

}
